package com.zzyl.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.entity.NursingLevel;
import com.zzyl.mapper.NursingLevelMapper;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * ClassName:NursingLevelServiceImpl
 * package:com.zzyl.service.impl
 * description:
 *
 * @author 刘
 * @version 1.0
 * @Create 2024/6/2 10:25
 */
@Service
public class NursingLevelServiceImpl implements NursingLevelService {

    @Autowired
    private NursingLevelMapper nursingLevelMapper;

    /**
     * 查询所有护理等级
     * @return
     */
    @Override
    public List<NursingLevelVo> getAllLevel() {

        List<NursingLevelVo> list = nursingLevelMapper.getAllLevel();
        return list;
    }

    /**
     * 新增护理等级
     * @param nursingLevelDto
     */
    @Override
    public void insertLevel(NursingLevelDto nursingLevelDto) {
        NursingLevel nursingLevel = new NursingLevel();
        BeanUtils.copyProperties(nursingLevelDto,nursingLevel);
        nursingLevelMapper.insertLevel(nursingLevel);
    }

    /**
     * 条件分页查询
     * @param pageNum
     * @param pageSize
     * @param name
     * @param status
     * @return
     */
    @Override
    public PageResponse<NursingLevelVo> selectByLimit(Integer pageNum, Integer pageSize, String name, Integer status) {

        PageHelper.startPage(pageNum,pageSize);

        Page<NursingLevelVo> page = nursingLevelMapper.selectByLimit(name,status);

        PageResponse<NursingLevelVo> pageResponse = PageResponse.of(page, NursingLevelVo.class);

        return pageResponse;
    }

    /**
     * 根据id查询护理等级
     * @param id
     * @return
     */
    @Override
    public NursingLevelVo selectById(Integer id) {
        NursingLevelVo nursingLevelVo = nursingLevelMapper.selectById(id);
        return nursingLevelVo;
    }

    /**
     * 编辑修改
     * @param nursingLevelDto
     */
    @Override
    public void updateLevel(NursingLevelDto nursingLevelDto) {

        NursingLevel nursingLevel = new NursingLevel();
        BeanUtils.copyProperties(nursingLevelDto,nursingLevel);
        nursingLevelMapper.updateLevel(nursingLevel);
    }

    /**
     * 删除
     * @param id
     */
    @Override
    public void deleteLevel(Integer id) {
        nursingLevelMapper.deleteLevel(id);
    }

    /**
     * 禁用启用
     * @param id
     * @param status
     */
    @Override
    public void updateStatusById(Integer id, Integer status) {
        nursingLevelMapper.updateStatusById(id,status);
    }
}
